const Router = require('koa-router');

const momentRouter = new Router({ prefix: '/moment' });

const {
  create,
  detail,
  list,
  update,
  remove,
  addLabels,
  fileInfo,
} = require('../controller/moment.controller');
const { verifyAuth, veriPermission } = require('../middleware/auto.middleware');

const { verifyLabelExists } = require('../middleware/label.middleware');

momentRouter.post('/', verifyAuth, create);
momentRouter.get('/', list);
momentRouter.get('/:momentId', detail);

//用户必须登陆，2.用户具备权限
momentRouter.patch('/:momentId', verifyAuth, veriPermission, update);
momentRouter.delete('/:momentId', verifyAuth, veriPermission, remove);

//给动态添加标签
momentRouter.post(
  '/:momentId/labels',
  verifyAuth,
  veriPermission,
  verifyLabelExists,
  addLabels
);

//动态配图的服务
momentRouter.get('/images/:filename', fileInfo);

module.exports = momentRouter;
